<?php

/**
 * page actions.
 *
 * @package    DUYTAN
 * @subpackage page
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class variableListAction extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeVariableList(sfWebRequest $request)
  {
	$this->variable_form = new AdminVariableForm();
	if ($request->hasParameter('create') && $request->getParameter('create') == 'Create') {
		$res = $request->getParameter('variable'); // get form variable
		$this->is_create_action = true;
		if ($res['variable_name'] != '') {
			$variable = new VTNSVariable();
			$variable->variable_name = $res['variable_name'];
			$variable->variable_type = $res['variable_type'];
			$variable->variable_value = $res['variable_value'];
			if ($res['is_active'] && $res['is_active'] == 'on')
				$variable->is_active = 1;
			else
				$variable->is_active = 0;
			
			try {
				$variable->save();
				$this->create_success = true;
			} catch (sfException $e) {
				echo $e->getMessage();
			}
		}
		
	} else {
		$variable_types = VTNSVariable::$variable_types;
		$result = array();
		foreach ($variable_types as $key=>$var_temp)
		{
			$temp = array();
			$q = Doctrine_Query::create()
					->from('VTNSVariable c')
					->where('variable_type = ?', $key);
			$temp['var_type_name'] = $var_temp;
			$temp['var_obj'] = $q->fetchArray();
			$result[] = $temp;
		}
		$this->result = $result;
		if ($request->isXmlHttpRequest()) {
        	return 'Ajax';
    	} else return SfView::SUCCESS;
	}
  }
}
